package com.dou.sample.opengl_project;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

/**
 * Created by Dou on 2018/1/15.
 */

public class FlatColorSquare extends Square {

    FloatBuffer colorFloatBuffer;

    float[] colors = {
            1,0,0,1, // 1 red
            0,1,0,1, // 2 green
            0,0,1,1, // 3 blue
            1,0,1,1, //magenta
    };

    public FlatColorSquare(){
        super();
        ByteBuffer colorByteBuffer = ByteBuffer.allocateDirect(colors.length * 4);
        colorByteBuffer.order(ByteOrder.nativeOrder());
        colorFloatBuffer = colorByteBuffer.asFloatBuffer();
        colorFloatBuffer.put(colors);
        colorFloatBuffer.position(0);
    }

    @Override
    public void draw(GL10 gl) {
//        gl.glColor4f(.5f,.5f,1,1);
        gl.glVertexPointer(3, GL10.GL_FLOAT,0, vertexBuffer);
        gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
        gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorFloatBuffer);
        super.draw(gl);
        gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
    }
}
